home *** CD-ROM | disk | FTP | other *** search
- /*************************************************************************************
- TTileGrid.h
-
- A TileGrid is a class that describes a 2 dimensional array of tiles that can be
- drawn as the background for a game. This current version only supplies
- graphics routines, but collision and other logic should be fairly easy to
- generate.
-
- Author: Timothy Carroll
- Apple Developer Technical Support
- timc@apple.com
-
- Modification History:
-
- 8/15/96 TMC Initial Release
-
- Copyright © 1996 Apple Computer, Inc., All Rights Reserved
-
- You may incorporate this sample code into your applications without
- restriction, though the sample code has been provided "AS IS" and the
- responsibility for its operation is 100% yours. However, what you are
- not permitted to do is to redistribute the source as "DSC Sample Code"
- after having made changes. If you're going to re-distribute the source,
- we require that you make it clear in the source that the code was
- descended from Apple Sample Code, but that you've made changes.
- *************************************************************************************/
-
- #ifndef _TTILEGRID_
- #define _TTILEGRID_
-
- #pragma once
-
- #include "TTileCollection.h"
- #include "GridTilesFormat.h"
-
-
- #if PRAGMA_STRUCT_ALIGN
- #pragma options align=power
- #endif
-
-
-
-
- class TTileGrid {
-
- public:
-
- /*************************************************************************************
- Constructor/Destructor
-
- Constructor is mostly used to initialize the object to a clean and known state, but
- doesn't do any actual work. The actual work of creating the object is a later call.
-
- The Destructor frees all allocated memory and releases the link to the Tile Collection.
-
- *************************************************************************************/
-
- TTileGrid (void);
- ~TTileGrid (void);
-
- /*************************************************************************************
- Creating a TileGrid.
-
- A TileGrid (by default) is loaded from a resource, although the potential exists to
- create other methods of creating the tile grid.
-
- *************************************************************************************/
- OSErr CreateGridFromResource (SInt16 resID);
-
-
- /*************************************************************************************
- Accessors
-
- A couple of accessors are provided for looking up the grid values. By default, if
- the h and v are outside the grid bounds, we return the "defaultTile" value.
-
- *************************************************************************************/
-
- CellGridType GetGridValue (SInt32 h, SInt32 v);
- void SetGridValue (SInt32 h, SInt32 v, CellGridType value);
-
- SInt32 GetGridWidth (void) { return fWidth;};
- SInt32 GetGridHeight (void) { return fHeight;};
-
- /*************************************************************************************
- Drawing
-
- This routine takes a point in 16.16 global space, and the clipping rectangle in screen
- coordinates, and does all the right things to draw the grid inside the entire clip rect.
-
- *************************************************************************************/
-
- void DrawGrid (Rect *screenRect, SInt32 topGlobal, SInt32 leftGlobal);
-
-
- /*************************************************************************************
- Data for a TileGrid object.
-
- *************************************************************************************/
-
- protected:
-
- SInt32 fWidth;
- SInt32 fHeight;
- UInt32 fDefaultTile; // used to draw all out of bounds tiles.
- TTileCollection *fTiles;
- CellGridType **fTileData; // variable length array of cell data.
- };
-
- #if PRAGMA_STRUCT_ALIGN
- #pragma options align=reset
- #endif
-
-
- #endif /* _TTILEGRID_ */
-